<?php

namespace support\storage\engine;


use JohnLui\AliyunOSS;
use OSS\OssClient;

/**
 * 阿里云OSS 引擎
 */
class Alioss extends Server
{
    private $config;



    private $ossClient;

    /**
     * 构造方法
     * Qiniu constructor.
     * @param $config
     * @throws \think\Exception
     */
    public function __construct($config)
    {
        parent::__construct();
        $this->config = $config['config'];
        $this->ossClient = new OssClient(
            $this->config['access_key'],
            $this->config['secret_key'],
            $this->config['endpoint']
        );
    }

    /**
     * 执行上传
     * @return bool|mixed
     * @throws \Exception
     */
    public function upload()
    {
        // 上传目录
        $this->filePath = 'oss/';
        $realPath = $this->file->getRealPath();
        return $this->ossClient->uploadFile($this->config['bucket'],$this->filePath.$this->fileName, $realPath);
    }

    /**
     * 返回文件路径
     * @return mixed
     */
    public function getFileName()
    {
        return $this->fileName;
    }

    /**
     * 返回文件路径
     * @return mixed
     */
    public function getFilePath()
    {
        return $this->filePath;
    }

    public function getUniqueId()
    {
         return $this->unique_id;
    }

}